<?php
/**
 * Created by PhpStorm.
 * User: zhonghuanglin
 * Date: 02/09/2017
 * Time: 10:53
 *
 * Usage:
 *  php socketio.php start
 *
 * 打开·socketio/example/clienta.html··socketio/example/clientb.html·，查看控制台
 * 打开下面的链接即可推送消息：
 *  http://localhost:1993/?function=transmit&to=clienta&from=linzh&content=thisiscontent
 *
 */

namespace {

//    spl_autoload_register(function ($clsnm) {
//        $relapath = str_replace('\\', '/', $clsnm);
//        $file = __DIR__ . '/../../' . $relapath . '.php';
//        is_file($file) and require($file);
//    });
    require __DIR__.'/../engine.inc';
    require __DIR__ . '/../plugin/Workerman/Autoloader.php';
    require __DIR__ . '/../plugin/PHPSocketIO/autoload.php';
    require __DIR__ . '/../plugin/Channel/Client.php';
    require __DIR__ . '/../plugin/Channel/Server.php';

    use Workerman\Connection\TcpConnection;
    use PHPSocketIO\Socket;
    use inframe\service\socketio\SocketIOServer as SocketServer;
    use inframe\service\socketio\Message;
    use inframe\service\socketio\EventHandlerInterface;


    class SocketEventHandler implements EventHandlerInterface
    {
        public function connect(Socket $clientServer, SocketServer $clientServerServer): bool
        {
            return true;
        }

        public function register(Message $message, Socket $clientServer, SocketServer $clientServerServer): bool
        {
            return true;
        }

        public function request(TcpConnection $connection, array $env, SocketServer $context)
        {
            echo "[request]";
            return false;
        }

        public function disconnect(Socket $clientServer, SocketServer $clientServerServer)
        {
            echo "[{$clientServer->id} disconnect]";
        }

        public function message(Message $message, Socket $clientServer, SocketServer $clientServerServer)
        {
        }
    }

    $server = new SocketServer();
    $server->setHandler(new SocketEventHandler());
    $server->start();


}